package xyz.yuzegod.megawalls.classes.novice.him;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.ClassesManager;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;

import java.util.ArrayList;
import java.util.List;

public class ThirdSkill extends Skill
{
    public ThirdSkill(final Classes classes) {
        super("飓风", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 5.0;
            }
            case 2: {
                return 4.0;
            }
            case 3: {
                return 3.0;
            }
            default: {
                return 5.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7每§a" + this.getAttribute(level) + "§7次攻击,获得");
            lore.add("   §7速度 II 和生命恢复 II 持续3秒");
            return lore;
        }
        lore.add(" §8▪ §7每§8" + this.getAttribute(level - 1) + " ➜ §a" + this.getAttribute(level) + "§7次攻击,获得");
        lore.add("   §7速度 II 和生命恢复 II 持续3秒");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill3Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill3Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        final int maxAttack = (int)this.getAttribute(gamePlayer.getPlayerStats().getKitStats(ClassesManager.getSelected(gamePlayer)).getSkill3Level());
        final int attack = HIM.skill3.getOrDefault(gamePlayer, maxAttack);
        if (attack == maxAttack) {
            HIM.skill3.put(gamePlayer, 1);
            return true;
        }
        final int i = attack + 1;
        HIM.skill3.put(gamePlayer, i);
        if (i == maxAttack) {
            final Player player = gamePlayer.getPlayer();
            if (player.hasPotionEffect(PotionEffectType.SPEED)) {
                player.removePotionEffect(PotionEffectType.SPEED);
            }
            player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1));
            if (player.hasPotionEffect(PotionEffectType.REGENERATION)) {
                player.removePotionEffect(PotionEffectType.REGENERATION);
            }
            player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 60, 1));
        }
        return true;
    }
    
    @Override
    public String getSkillTip(final GamePlayer gamePlayer) {
        final int skillLevel = gamePlayer.getPlayerStats().getKitStats(ClassesManager.getSelected(gamePlayer)).getSkill3Level();
        final int attack = HIM.skill3.getOrDefault(gamePlayer, (int)this.getAttribute(skillLevel));
        return this.getClasses().getNameColor() + "§l" + this.getName() + " " + ((attack == (int)this.getAttribute(skillLevel)) ? "§a§l✓" : ("§a§l" + attack));
    }
}
